import React, { Component } from 'react'
import { connect } from 'dva';
import Link from 'umi/link';
import { Form, Input, DatePicker } from 'antd';
import { SearchRow, SearchCol, SearchButton } from '@/styled/form';
import { DropDownSelect } from '@/components/DropDownSelect/index';
import moment from 'moment';
// import { DICT } from '../enum';

interface IProps {
  current: number,
  form: any,
  dispatch?: Function,
  initCurrent: Function,
  onAdd: Function,
  new: boolean,
  dict?: any,
  cond?: any
}

const FormItem = Form.Item;
const ONE_PAGE_SIZE = 10;

@connect(({ archives_unit }) => ({
  editingKey: archives_unit.editingKey,

}))
// @connect(({ fireroom }) => ({
//   dict: fireroom.dict,
//   cond: fireroom.cond
// }))
class Search extends Component<IProps, any> {

  componentDidMount() {
    const { dispatch } = this.props;

    // dispatch({ type: 'fireroom/queryDict', payload: { keyList: DICT } }).then(() => {
    //   const { cond, form } = this.props;
    //   const {pageNum, pageSize, ...searchParams} = cond;
    //   form.setFieldsValue(searchParams);
    // });
  }

  search = e => {
    e.preventDefault();
    const { dispatch, form, initCurrent } = this.props;
    form.validateFields((err, values) => {

      let auditTimeStr = values.auditTimeStr ? moment(values.auditTimeStr).format("YYYY-MM-DD") : null;
      // moment(buildTime, 'YYYY-MM-DD')
      if (!err) {
        dispatch({
          type: 'archives_unit/updateDocumentCond',
          payload: {
            ...values,
            auditTimeStr
          }
        })

        // initCurrent()
      }
    });
  }

  render() {
    const { dict = {}, form } = this.props;
    const { getFieldDecorator } = form;
    const formItemLayout = {
      labelCol: { span: 10 },
      wrapperCol: { span: 14 },
    };

    return (
      <Form onSubmit={this.search}>
        <SearchRow>
          <SearchCol key={0} span={5}>
            <FormItem
              label="文件(证书)名称"
              {...formItemLayout}
            >
              {getFieldDecorator('name', {
                rules: [{ message: '输入文件(证书)名称' }],
              })(
                <Input style={{width: '100%'}} placeholder="请输入" />
              )}
            </FormItem>
          </SearchCol>
          <SearchCol key={1} span={5}>
            <FormItem
              label="编号(文号)"
              {...formItemLayout}
            >
              {getFieldDecorator('certificateNo')(
                <Input style={{width: '100%'}} placeholder="请输入" />
              )}
            </FormItem>
          </SearchCol>
          <SearchCol key={2} span={4}>
            <FormItem
              label="审批时间"
              {...formItemLayout}
            >
              {getFieldDecorator('auditTimeStr')(
                <DatePicker
                  showTime
                  {...getFieldDecorator('auditTimeStr')}
                  format={'YYYY-MM-DD'}
                  style={{ width: '100%' }}
                  placeholder="请选择"
                  // onChange={(v) => this.handleChangeTime(v)}
                />
              )}
            </FormItem>
          </SearchCol>
          <SearchCol key={4} span={4}></SearchCol>
          {/* <SearchCol key={5} span={4}></SearchCol> */}
          <SearchCol key={3} span={4} justify="end">
            <SearchButton htmlType="submit">搜索</SearchButton>
            <SearchButton disabled={this.props.editingKey !== ''} onClick={this.props.onAdd} type="primary">新增</SearchButton>
          </SearchCol>
        </SearchRow>
      </Form>
    );
  }
}

const SearchS = Form.create()(Search);
export default SearchS;
